package com.pig4cloud.pig.itinerary.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.security.util.SecurityUtils;
import com.pig4cloud.pig.itinerary.api.dto.TrItineraryAddDTO;
import com.pig4cloud.pig.itinerary.service.TrItineraryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.security.Security;

@RestController
@RequiredArgsConstructor
@RequestMapping("/itinerary")
@Tag(description = "itinerary", name = "行程库管理")
public class TrItineraryController {
	@Autowired
	private TrItineraryService trItineraryService;
	/**
	 * 根据条件获取行程库内容
	 */
	@GetMapping("/selectItineraryByCondition")
	public R listTripsByInquireNumOrTel(
			Page page,
			@RequestParam(required = false) String itineraryName,
			@RequestParam(required = false) String createBy) {
		System.out.println(SecurityUtils.getRoles());

		return R.ok(trItineraryService.selectItineraryByCondition(page,itineraryName,createBy));
	}
	/**
	 * 删除行程库内容通过id
	 */
	@DeleteMapping("/deleteItinerary")
	public R deleteItinerary(@RequestParam Long itineraryId) {
		System.out.println(SecurityUtils.getRoles());
		return R.ok(trItineraryService.removeByItineraryId(itineraryId));
	}
	/**
	 * 批量删除行程库内容通过id
	 */
	@DeleteMapping("/deleteBatch")
	public R deleteBatch(@RequestBody Long[] itineraryIds) {
		return R.ok(trItineraryService.removeByItineraryIds(itineraryIds));
	}
	/**
	 * 新增行程库添加行程库内容
	 */
	@PostMapping
	@Operation(summary = "新增行程库及内容")
	public R<Long> add(@RequestBody TrItineraryAddDTO dto) {
		// 可以在这里添加参数校验逻辑
		Long itineraryId = trItineraryService.addItineraryWithContent(dto);
		return R.ok(itineraryId, "新增成功");
	}
	/**
	 *
	 */
}
